'use strict'
module.exports = (app) => {
  const { INTEGER, DATE } = app.Sequelize
  // 配置（重要：一定要配置详细，一定要！！！）
  const Feedback = app.model.define('feedback', {
    id: {
      type: INTEGER(20).UNSIGNED,
      primaryKey: true,
      autoIncrement: true
    },
    leaveword_id: {
      type: INTEGER(20).UNSIGNED,
      allowNull: false,
      comment: '留言id',
      references: {
        model: 'leaveword',
        key: 'id'
      },
      onUpdate: 'restrict',
      onDelete: 'cascade'
    },
    user_id: {
      type: INTEGER(20).UNSIGNED,
      allowNull: false,
      comment: '用户id',
      references: {
        model: 'user',
        key: 'id'
      },
      onUpdate: 'restrict',
      onDelete: 'cascade'
    },
    type: {
      type: INTEGER(1),
      allowNull: false,
      defaultValue: 1,
      comment: '反馈类型-1:喜欢,2:举报'
    },
    created_time: {
      type: DATE,
      get() {
        return app.formatTime(this.getDataValue('created_time'))
      }
    }
  })
  // 关联关系
  Feedback.associate = (models) => {
    // 关联留言的id  多对一
    Feedback.belongsTo(app.model.Leaveword, { foreignKey: 'leaveword_id' })
    Feedback.belongsTo(app.model.User, { foreignKey: 'user_id' })
  }
  return Feedback
}
